<template>
  <div class="home-container">
    <Header />
    <el-carousel class="carousel" autoplay>
      <el-carousel-item v-for="(item, index) in carouselItems" :key="item.id">
        <img :src="item.img_http" alt="轮播图"/>
      </el-carousel-item>
    </el-carousel>

    <div class="content">
      <h2>热门旅游目的地</h2>
      <div class="destination-list">
        <div class="destination-item" v-for="(destination, index) in destinations" :key="destination.id">
          <img :src="destination.img_http" alt="目的地" />
          <h3>{{ destination.title }}</h3>
        </div>
      </div>
    </div>

    <OneList v-for="(item,index) in onListdata" :key="item.id" :props-data="item"/>
    <Footer />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { homeNavImgApi,CityList } from '@/api'
import type { NavImg,OneListForm } from '@/types/tuil'

// 轮播图的获取
const carouselItems= ref<NavImg[]>([])
// 三个列表的获取
const destinations = ref<NavImg[]>([])
// 这里是用来获取列表的
const onListdata = ref<OneListForm[]>()
onMounted(async () => {
  //页面加载的时候导入轮播图图片
  const res1 = await homeNavImgApi.getHomeNavImg()
  const res2 = await homeNavImgApi.getNavImg3()
  // 这里是获取城市列表(景点列表的)
  const res3 = await CityList.getCityListByHome()
  console.log(res1)
  carouselItems.value = res1
  destinations.value = res2
  onListdata.value = res3
})



</script>

<style scoped>
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.carousel {
  width: 100%;
  height: 400px;
}

.carousel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content {
  width: 100%;
  max-width: 1200px;
  padding: 20px;
  text-align: center;
}

.destination-list {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

.destination-item {
  width: 30%;
  margin: 10px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s;
}

.destination-item:hover {
  transform: scale(1.05);
}

.destination-item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

</style>